/**
 * Copyright 2008-2009 HAN.BIFANG
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package han.bifang.gwt.client.config;

import han.bifang.gwt.client.common.GwtContext;
import han.bifang.gwt.client.communicate.BifangGWTServiceAsync;
import han.bifang.gwt.client.config.content.AdminTab;
import han.bifang.gwt.client.config.content.ProviderTab;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SourcesTabEvents;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * 
 * @Author Kent
 */
public class ConfigTab extends Composite {
	private ConfigMessages cons = null;

	private BifangGWTServiceAsync service = null;

	private GwtContext context = null;

	private VerticalPanel panel = null;
	
	private TabPanel tabs;
	
	
	public ConfigTab(BifangGWTServiceAsync service, GwtContext context) {
		this.service = service;
		this.context = context;
		
		cons = GWT.create(ConfigMessages.class);
		panel = new VerticalPanel();
		panel.setWidth("100%");
		
		
		
		
		initWidget(panel);
	}
	
	public void onLoad(){
		tabs = new TabPanel(){
			public boolean onBeforeTabSelected(SourcesTabEvents sender,
					int tabIndex) {
				
				if (tabIndex == 0){
					AdminTab t = (AdminTab)tabs.getWidget(0);
					t.init();
				}else if(tabIndex == 1){
					ProviderTab t = (ProviderTab)tabs.getWidget(1);
					t.init();
				}
					
				return true;
			}
		};
		
		tabs.add(new AdminTab(cons, service, context), cons.admin());
		tabs.add(new ProviderTab(cons, service, context), cons.provider());
		tabs.setWidth("100%");
		tabs.selectTab(0);
		panel.add(tabs);
	}
	
	

}
